//#pragma large
#include <REGX52.H>
#include "mouse.h"  //page 163    177
#include "Delay.h"
#include "Power.h"
#include "Timer2.h"
#include "dfs1.h"
#include "dash.h"
bit  irC = 0, irL=0, irR=0, irLU=0, irRU=0;
//sbit tube0 = P1^6;
//sbit tube1 = P1^7;																
//设置 T2 自动重载寄存器和计数器初值
void UartInit(void)		//4800bps@11.0592MHz
{
  PCON |= 0x80;		//????????SMOD
	SCON = 0x50;		//8???,?????
	TMOD &= 0x0F;		//?????1???
	TMOD |= 0x20;		//?????1?8???????
	TL1 = 0xF4;		//??????
	TH1 = 0xF4;		//????????
	ET1 = 0;		//?????1??
	TR1 = 1;		//?????1
}
void main()
{
	Delay(1000);
	initTime2();//初始化 T2
	UartInit();
//	while(1){
//	if(irLU == 1){
//		beep = 0;
//		Delay(10);
//		beep = 1;
//		Delay(500);
//	}
//	}
	dfs1();
	Delay(200) ;
	TurnRight();
	TurnRight();
	creat_table();
	find_min();
	dash();
	beep = 0;
	Delay(1000);
	beep =1;
}
//T2 中断服务函数
void time2() interrupt 5
{
	static bit ir=0;
	static char n=1;
	TF2=0;
	if(!ir)
	{
		MOUSE_IR_ON(n-1);
	}
	else
	{
		//可以用switch 实现
		if(n==1)
		{
			if(irR1) irC=0;  //前无墙
			else //前有墙
			{	
				irC = 1;
			}
		}
		else if(n==2)
		{
			if(irR2) irLU=0;//左前无墙
			else //左前有墙
			{
				irLU=1;
			}
		}
		else if(n==3)
		{
			if(irR3) irL=0;//左无墙
			else //左有墙
			{
				irL=1;
			}
		}
		else if(n==4)
		{
			if(irR4) irR=0;//右无墙
			else //右有墙
			{
				irR=1;
			}
		}
		else if(n==5)
		{
			if(irR5) irRU=0;//右前无墙
			else //右前有墙
			{
				irRU=1;
			}
		}
	}
	if(ir) n++;
	if(n>5) n = 1;
	ir=~ir;
//改变接收、发射状态
}